package com.project.webservice.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.webservice.dto.JgGjxlView;
import com.project.webservice.dto.JgGjxlzdViewDto;
import com.project.webservice.util.JSONUtils;
import com.project.webservice.entity.JgGjxl;
import com.project.webservice.mapper.JgGjxlMapper;
import com.project.webservice.service.JgGjxlService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
@DS("master")
public class JgGjxlServiceImpl extends ServiceImpl<JgGjxlMapper, JgGjxl> implements JgGjxlService {

    /**
     *
     * @param JgGjxl
     * @return
     */
    public List<JgGjxl> searchByList(JgGjxl JgGjxl){
        log.info("searchByList:{}", JSONUtils.writeExcludeNull(JgGjxl));
        return list(Wrappers.<JgGjxl>lambdaQuery());
    }


    /**
     *
     * @param jgxlid
     * @return
     */
    public JgGjxl searchById(Integer jgxlid){
        return getById(jgxlid);
    }
    /**
     * 分页
     * @param page
     * @param JgGjxl
     * @return
     */
    public IPage searchByPage(Page page, JgGjxl JgGjxl){
        log.info("searchByPage:{}", JSONUtils.writeExcludeNull(JgGjxl));
        return baseMapper.selectPage(page, Wrappers.<JgGjxl>lambdaQuery());
    }

    /**
     * 根据yhids查询
     * @param yhids
     * @return
     */
    public List<JgGjxl> searchByListByYhids(List<String> yhids){
        return super.list(Wrappers.<JgGjxl>lambdaQuery().eq(JgGjxl::getState,0).in(JgGjxl::getYhid,yhids));
    }

    /**
     *
     * @param search
     * @return
     */
    public List<JgGjxlzdViewDto> searchJgGjxlzdView(JgGjxlzdViewDto search){
        log.info("searchJgGjxlzdView:{}", JSONUtils.writeExcludeNull(search));
        search.setSxx(1);
        List<JgGjxlzdViewDto> list = baseMapper.searchJgGjxlzdView(search);
        if(CollUtil.isEmpty( list)){ //如果返回记录是空，设置sxx为0
            search.setSxx(0);
            list = baseMapper.searchJgGjxlzdView(search);
        }
        return list;
    }

    /**
     * getLINE
     * @param line
     * @return
     */
    public List<JgGjxl> searchJgGjxlByLine(String line){
        log.info("searchJgGjxl:{}", line);
        return baseMapper.selectList(Wrappers.<JgGjxl>lambdaQuery().eq(JgGjxl::getState,0)
                .like(JgGjxl::getXlmc,line).last("limit 10").orderByAsc(JgGjxl::getXlmc));
    }

//    /**
//     * 查询视图
//     * @param yhids
//     * @return
//     */
//    public List<JgGjxlView> searchJgGjxlView(List<String> yhids){
//        return baseMapper.searchJgGjxlView(yhids);
//    }
}
